<template>
    <el-button plain type="primary"  @click="dialogVisible = true">
        新增 +
    </el-button>
        <el-dialog 
        v-model="dialogVisible" 
        title="添加权限" width="500" 
        :before-close="handleClose">
            <el-form
            ref="formRef"
            label-width="100px"
            label-position="left"
            :model="form">
            <el-form-item label="名称" prop="name">
                <el-input v-model="form.name" placeholder="请输入权限名称"></el-input>
            </el-form-item>
            <el-form-item label="权限" prop="permissions">
                <el-tree
                    ref="treeRef"
                    :data="permission"
                    style="max-width: 600px;"
                    node-key="id"
                    :show-checkbox="true"
                    :default-checked-keys="defaultKeys"
                />

            </el-form-item>
        </el-form>
        <template #footer>
            <div class="dialog-footer">
                <el-button @click="dialogVisible = false">取消</el-button>
                <el-button type="primary" @click="dialogVisible = false">
                    确定
                </el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script lang="ts" setup>
import { ref , reactive, onMounted} from 'vue'
import { ElMessageBox } from 'element-plus'
import { userGetMenu } from '../../../api/authGroup.js'


//form的数据
const form = reactive({
    name:'',
    permissions:'',
})
//菜单权限的数据
const permission = ref([])

//默认选中的权限
const defaultKeys =[4,5]


onMounted(async() =>{
    const res = await userGetMenu()
    permission.value = res.data
    
})

const treeRef = ref()














//弹窗
const dialogVisible = ref(false)
const handleClose = (done: () => void) => {
    ElMessageBox.confirm('确定关闭吗?')
        .then(() => {
            done()
        })
        .catch(() => {
            // catch error
        })
}
</script>